import { ajax } from "../../../utils/request";

// components/mine/coupon/coupon-list.ts
Component({
  created() {
    this.setData({ showList: this.data.couponList });
    console.log('星期二', this.data.showList);
  },
  /**
   * 组件的属性列表
   */
  properties: {
    value: {
      type: Number
    },
    selectValue: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isselected: null,
    selectValue: 0,
    showList: [],
    couponList: [],
    usedList: []
  },
  /**
   * 组件的方法列表
   */
  methods: {
    handleHighLight(e: any) {
      // console.log('eee',e.currentTarget.dataset.id);
      let isselected = e.currentTarget.dataset.id;
      // 这里忘记setdata数据了 数据没更新 所以isselected的值一直都是false
      this.setData({ isselected });
    }
  },
  //侦听属性变化
  observers: {
    "value": function (value) {
      console.log("value", value);
      if (value == 1) {
        let usedList = [
          { id: 0, name: "100元", deadline: "2022-07-27" },
          { id: 1, name: "200元", deadline: "2022-07-27" },
          { id: 2, name: "300元", deadline: "2022-07-27" }
        ];
        this.setData({ showList: usedList });
        console.log('展示列表', this.data.showList);
      }
      if (value == 0) {
        //请求后端，用响应数据替换allList
        let allList = [
          { id: 0, name: "5元", deadline: "2022-07-27" },
          { id: 1, name: "6元", deadline: "2022-07-27" },
          { id: 2, name: "7元", deadline: "2022-07-27" },
          { id: 3, name: "8元", deadline: "2022-07-27" },
          { id: 4, name: "5元", deadline: "2022-07-27" },
          { id: 5, name: "6元", deadline: "2022-07-27" },
          { id: 6, name: "7元", deadline: "2022-07-27" },
          { id: 7, name: "8元", deadline: "2022-07-27" },
        ];
//         ajax("/kkk/",{},'POST').then((res:any)=>{
//         let listdata=res.dataset.
//         }),
        this.setData({ showList: allList });
        console.log('展示列表', this.data.showList);
      }
    },
    "isselected": function (value) {
      console.log('样式', value, this.data.isselected);
    },
    "selectValue": function (value) {
      console.log('父组件船只', value);
    }

  },

})
